﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebShopData;

namespace GalaxySale2014
{
    public partial class Site : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            User currentUser = Session["CurrentUser"] as User;
            if (currentUser == null)
            {
                Response.Redirect(@"~/Login.aspx");
            }
            LabelUserName.Text = string.Format("Logged in as: {0}", currentUser.UserName);
            Order order = Session["CurrentOrder"] as Order;
            if (order.OrderRows.Count == 0)
            {
                DropDownListCart.Visible = false;
            }
            else
            {
                DropDownListCart.DataSource = order.OrderRows;
                DropDownListCart.DataBind();
                DropDownListCart.Visible = true;
            }
            if (Session["AddToCartText"] != null)
            {
                LabelAddToCartText.Text = Session["AddToCartText"].ToString();
                Session["AddToCartText"] = null;
            }
        }

        protected void ButtonLogOut_Click(object sender, EventArgs e)
        {
            Session["CurrentUser"] = null;
            ((Order)Session["CurrentOrder"]).OrderRows.Clear();
            Response.Redirect("~/Login.aspx");
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}